package com.neusoft.neu24.his.hisapp;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.util.Pair;
import javafx.util.StringConverter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class HelloApplication_ChoiceBox_1 extends Application {

    private final ChoiceBox<Pair<String,String>> assetClass = new ChoiceBox<>();
    private final static Pair<String, String> EMPTY_PAIR = new Pair<>("", "");

    @Override
    public void start(Stage stage) throws IOException {

        Label label = new Label("Asset Class:");
        assetClass.setPrefWidth(200);
        Button saveButton = new Button("Save");
//  ActionEvent evt
        saveButton.setOnAction( (evt)->{
            System.out.println("Asfsadf a");

        } );

        HBox hbox =new HBox();
        hbox.getChildren().addAll(label,assetClass,saveButton);
        hbox.setSpacing( 10.0d );
        hbox.setAlignment(Pos.CENTER );
        hbox.setPadding( new Insets(40) );







        Scene scene = new Scene(hbox, 1280, 768);
        stage.setTitle("Hello!");
        stage.setScene(scene);
        stage.show();

        initChoice();
    }

    private void initChoice() {
        List<Pair<String,String>> assetClasses = new ArrayList<>();
        assetClasses.add( new Pair("男", "男"));
        assetClasses.add( new Pair("Furniture", "21000"));
        assetClasses.add( new Pair("Investment", "22000"));

        assetClass.setConverter( new StringConverter<Pair<String,String>>() {
            @Override
            public String toString(Pair<String, String> pair) {
                return pair.getKey();
            }

            @Override
            public Pair<String, String> fromString(String string) {
                return null;
            }
        });

        assetClass.getItems().add( EMPTY_PAIR );
        assetClass.getItems().addAll( assetClasses );
        assetClass.setValue( EMPTY_PAIR );

    }

    public static void main(String[] args) {
        launch();
    }
}